package com.tcm.doctor.web.handler;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.doctor.web.exception.TokenRuntimeException;
import io.jsonwebtoken.SignatureException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class RuntimeExceptionHandler {
 
  @ExceptionHandler(TokenRuntimeException.class)
  public R tokenRuntimeException(TokenRuntimeException e) {
    e.printStackTrace();
    return R.fail(e.getCode(), e.getMessage());
  }

  @ExceptionHandler(SignatureException.class)
  public R signatureException(Exception e){
    e.printStackTrace();
    return R.fail("非法的token");
  }

  @ExceptionHandler(Exception.class)
  public R handlerException(Exception e){
    e.printStackTrace();
    return R.fail("系统未知异常");
  }

  @ExceptionHandler(ServiceException.class)
  public R serviceException(ServiceException e){
    e.printStackTrace();
    return R.fail(e.getResult().getCode(),e.getMessage());
  }
}